home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
234_01
/
ctlr.c
< prev
next >
Wrap
Text File
|
1987-06-16
|
23KB
|
872 lines
/*
HEADER: CUG nnn.nn;
TITLE: XDIR - Hard Disk Manager
VERSION: 1.0 for IBM-PC
DATE: Apr 03, 1987
DESCRIPTION: Hard Disk Manager for IBM PC
KEYWORDS: Hard Disk Manager Dump Directory
SYSTEM: IBM-PC and Compatiables
FILENAME: ctlr.C
WARNINGS: None
CRC: N/A
SEE-ALSO: HDIR.DOC and XDIR.DOC
AUTHOR: Mike Blakley 15645 SW 82 Cir Ln #76, Miami, Fl 33193
COMPILERS: ECO-C
REFERENCES: XDIR.DOC
*/
/*
ctlr
display main menu screen for word search
process request
*/
#include "stdio.h"
#include "dos.h"
#include "dir.h"
/*
xscr.h
header file for scan function of XDIR
*/
/* xscan functions */
int xscan(char *fnam, char string[10][80],int ans[],char *options);
int sbuff(char *buff,char *string, int max, char *options);
int strxcmp(char *buff1, char *buff2, int maxlen, char *options);
int strxchr(char *buff, char c, int max);
/* xword functions */
void xword(char *buffer,char words[10][80]);
/* xscr functions */
int ctlr(char *fnam);
int xscr(char *fnam, char *xnam, char *stext,
int *sflag, int *stype, char *ext, char *opts);
int getitem(int *item, int row, int col, char *text, int len);
void sepname(char *all, char *path, char *file);
void cline(int row, int col, int len);
/* sdir functions */
int sdir(char *buff, char *filename, int action, char ext[10][80],int type);
int cmpext(char *fnam, char *ext);
/*********** end of header definition *************************/
/*
main()
{
ctlr("\\bin\\xdir.exe");
}
*/
/*
ctlr
controller module
*/
ctlr(fnam)
char *fnam;
{
int i,j, k, sflag, stype;
char xnam[80], stext[80], extents[80];
int ans[10]; /* answer for search */
char words[10][80]; /* words to search */
char filename[20]; /* work area for file name */
char extnames[10][80]; /* extent names */
char options[80]; /* search options */
struct {
char snam[40]; /* search file name */
int sopts[10]; /* search hits */
} sfiles[100]; /* store max of 100 files */
int scount;
i = xscr(fnam,xnam,stext,&sflag,&stype,extents,options);
if (i == -1)
{writestr("\nSearch aborted ");
return(-1);
}
cursor(2,50);
writestr("Begin search ... ");
cursor(5,10);
writestr("SEARCHING ");
cursor(7,10);
writestr("Located ");
scount = 0;
for (i=0;i<10;i++) words[i][0] = 0; /* init */
xword(stext,words); /* xlate search text to words */
if (stype == 0) /* search a single file */
{
i = xscan(xnam,words,ans,options);
if (i != 1)
{
writestr("\nXscan failure ");
getch();
exit(0); /* scan failure */
}
for (i=j=0;i<10;i++)
if (ans[i] == 1) ++j; /* determine any hits */
if (j)
{
writestr("\nSearch words found in file ");
writestr(xnam);
for (i=0;i<10;i++)
if (ans[i]==1) {putchar('\n');writestr(words[i]);}
}
else
{
writestr("\nNo match found in file ");
writestr(xnam);
}
} /* end if stype = 0 */
else /* search a directory */
{
for (i=0;i<10;i++) extnames[i][0] = 0; /* init */
xword(extents,extnames); /* xlate search extents to words */
i = sdir(xnam,filename,1,extnames,sflag); /* open the directory */
while (i = sdir(xnam,filename,0,extnames,sflag))
{
cursor(5,23);
for (i=0;i<20;i++) putchar(' ');
cursor(5,23);
writestr(filename);
j = xscan(filename,words,ans,options); /* search the file */
if (j != 1)
{
writestr("\nXscan failure");
getch();
exit(0);
}
for (i=j=0;i<10;i++) if (ans[i] == 1) ++j; /* determine any hits */
if (j)
{
cursor(7,23);
for (i=0;i<20;i++) putchar(' ');
cursor(7,23);
if (scount < 100)
{
strcpy(sfiles[scount].snam,filename);
for (i=0;i<10;i++) sfiles[scount].sopts[i] = ans[i];
++scount;
}
for (i=0;i<10;i++)
if (ans[i]==1) {putchar(' ');writestr(words[i]);}
}
} /* end while */
} /* end if stype != 0 */
/*************** print out the results of search *************/
clrscr();
writestr("\nResults of search located text as follows: ");
for (i=k=0;((i<10)&&(words[i][0] != 0));i++) ++k;
for (i=0;i<scount;i++)
{
writestr("\nFile ");
writestr(sfiles[i].snam);
for (j=0;j<k;j++)
if (sfiles[i].sopts[j] == 1) {putchar(' ');writestr(words[j]);}
} /* end of dump loop */
writestr("\nPress any key to continue "); /* pause screen */
getch();
}
/*
xscan
scan a file for text strings
to be included with xdir upon completion of module
*/
#define BUFFSIZE 8000
int xscan(fnam,string,ans,options)
char *fnam;
char string[10][80]; /* search strings */
int ans[]; /* search results */
char *options; /* search options */
{
int fd, flen,i,j,k,l,m;
char *alloc(int amt);
char *buff;
/* char temp[20]; */
fd = open(fnam,0);
if (fd == EOF)
{
writestr("\nCan't open file ");
writestr(fnam);
return(-1);
}
buff = alloc(BUFFSIZE+1);
if (buff == NULL) return (-1);
for (i=0;string[i][0] != 0;i++) ans[i] = 0; /* init to false */
k = i; /* count of search strings */
flen = BUFFSIZE;
while (flen == BUFFSIZE)
{
for (j=l=0;l<k;l++) j += ans[l]; /* determine if search s/b ended
because all strings located */
if (j == k) break; /* yes, all found */
flen = read(fd,buff,BUFFSIZE);
for (i=0;string[i][0] != 0;i++)
{
if (ans[i] == 0) /* only test where no match yet */
{
m = xcomp(buff,string[i],options,flen); /* search buffer */
if (m == 0) ans[i] = 1; /* record answer */
}
}
}
free(buff); /* free the buffer */
close(fd); /* close the file */
return (1);
}
/*
xword
parse a string into words
*/
void xword(buffer,words)
char *buffer; /* buffer to parse */
char words[10][80];
{
int i, j, state;
char *cp, *cpo;
int c;
int num; /* used in octal numbers */
char temp[80];
int tflag; /* flag - current words in tic marks */
for (i=0;i<10;i++) words[i][0] = 0;
state = i = j = tflag = 0;
cp = buffer;
cpo = temp;
while (1)
{
c = (int) *cp++; /* get a character */
switch (state)
{
case 0: /* begin a new word */
tflag = 0;
cpo = temp;
if (c == 0) state = 98;
else if (c == ' ') state = 0; /* skip leading spaces */
else if (c == '\'') {tflag = 1;state = 1;}
else {*cpo++ = c;state = 1;}
break;
case 1: /* start a new word tick mark */
if (c == '\\') state = 2;
else if ((c == '\'') && tflag)
{*cpo = 0;state = 0;strcpy(words[i++],temp);}
else if ((c == ' ') && (tflag == 0))
{*cpo = 0;state = 0;strcpy(words[i++],temp);}
else if (c == 0) state=98;
else {*cpo++ = c;stat